package com.xikeda.controller;

import com.xikeda.model.CourierTable;
import com.xikeda.model.UserTable;
import com.xikeda.service.imp.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author Xiao Linqing
 * @date 2020/6/7 16:16
 */
@Controller
public class RegisterController{
     @Resource
     private RegisterService registerService;
     public RegisterService getRegisterService() {
        return registerService;
    }
    @Autowired
    public void setRegisterService(RegisterService registerService) {
        this.registerService = registerService;
    }
    @RequestMapping("/register")
    public String Register(HttpServletRequest request, HttpServletResponse response){
        return "register";
    }
    @RequestMapping("/xuanzezhuce")
    public String Register1(HttpServletRequest request,HttpServletResponse response){
       /* String true_name=request.getParameter("true_name");
        String password=request.getParameter("password");
        String user_name=request.getParameter("user_name");
        String telephone=request.getParameter("telephone");*/
        String ide=request.getParameter("ide");
        if(ide!=null&&!ide.equals("")){
            if(ide.equals("user")){
                UserTable userTable=new UserTable();
                userTable.setTrue_name(request.getParameter("true_name"));
                userTable.setPassword(request.getParameter("password"));
                userTable.setUser_name(request.getParameter("user_name"));
                userTable.setTelephone(request.getParameter("telephone"));
                this.getRegisterService().userregister(userTable);
            }
        }
        if(ide.equals("post")){
            CourierTable courierTable=new CourierTable();
            courierTable.setCourier_true_name(request.getParameter("true_name"));
            courierTable.setCourier_password(request.getParameter("password"));
            courierTable.setCourier_name(request.getParameter("user_name"));
            courierTable.setTelephone(request.getParameter("telephone"));
            this.getRegisterService().courierregister(courierTable);
        }
        return "login";
    }
    /*@RequestMapping("/userregister")
    @ResponseBody
    public void userregister(HttpServletRequest request,HttpServletResponse response){
        UserTable userTable=new UserTable();
        userTable.setTrue_name(request.getParameter("true_name"));
        userTable.setPassword(request.getParameter("password"));
        userTable.setUser_name(request.getParameter("user_name"));
        userTable.setTelephone(request.getParameter("telephone"));
        this.getRegisterService().userregister(userTable);
    }*/
   /* @RequestMapping("/courierregister")
    @ResponseBody
    public void courierregister(HttpServletRequest request,HttpServletResponse response){
        CourierTable courierTable=new CourierTable();
        courierTable.setCourier_true_name(request.getParameter("courier_true_name"));
        courierTable.setCourier_password(request.getParameter("courier_password"));
        courierTable.setCourier_name(request.getParameter("courier_name"));
        courierTable.setTelephone(request.getParameter("telephone"));
        this.getRegisterService().courierregister(courierTable);
    }*/
    /*@RequestMapping("/userregister")
    @ResponseBody
    public String register1(HttpServletRequest request, HttpServletResponse response)throws Exception{
        String true_name=request.getParameter("true_name");
        String password=request.getParameter("password");
        String user_name=request.getParameter("user_name");
        String telephone=request.getParameter("telephone");
        System.out.println(true_name);
        System.out.println(password);
        System.out.println(user_name);
        System.out.println(telephone);
        List<UserTable> list=this.getRegisterService().userregister(true_name,password,user_name,telephone);
        if(list!=null&&list.size()>0){
            for(UserTable li:list){
                System.out.println(li.getTrue_name());
                System.out.println(li.getPassword());
                System.out.println(li.getUser_name());
                System.out.println(li.getTelephone());
            }
        }
        return "demo";
     }*/

}
